package com.tsing.mapper.impl;

import com.tsing.common.framwork.mapper.CommonDao;
import com.tsing.common.result.PageResult;
import com.tsing.mapper.SearchMapper;
import com.tsing.pojo.entity.TlCollect;
import com.tsing.pojo.entity.TlDetails;
import com.tsing.pojo.entity.TlPost;

import java.sql.SQLException;
import java.util.List;

/**
 * @auth 卢孝宇
 * @date 2023/12/14 14:26
 */
public class SearchMapperImpl extends CommonDao implements SearchMapper {

    @Override
    public List<TlPost> list(String query) {
        List<TlPost> list = null;
        Object[] params = {query};

        try {
            list = executeQuery(TlPost.class, "select * from tl_post where title like concat('%',?,'%')", params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public List<TlPost> postList(String query, Integer page, Integer size) {
        int offset = (page - 1) * size;
        List<TlPost> list = null;

        Object[] params = {query,offset,size};
        try {
            list = executeQuery(TlPost.class, "select * from tl_post where title like concat('%',?,'%') limit ?,?",
                    params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    @Override
    public Integer countPost(String query) {
        Integer list = null;

        Object[] params = {query};
        try {
            list = executeCount( "select count(*) from tl_post where title like concat('%',?,'%')", params);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
